#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > r12_orb.info <<'%EOF%'
   r12_orb
   -----------
   Molecule:         Methane (CH4)
   Wave Function:    MP2-R12 / Turbomole-TZV
   Test Purpose:     Check R12 method with extra r12 pairs
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > r12_orb.mol <<'%EOF%'
BASIS
Turbomole-TZV Turbomole-TZVP
Direct MP2-R12/B calculation using symmetry

    4    2 XY XZ
 1      6.    1
C      0.000000000000000   0.000000000000000   0.000000000000000       *
 1      1.    1
H      1.276731000000000   1.276731000000000   1.276731000000000       *
 2      6.    1
C      0.000000000000000   0.000000000000000   0.000000000000000       *
 2      1.    1
H      1.276731000000000   1.276731000000000   1.276731000000000       *
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > r12_orb.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTION
.DIRECT
**INTEGRALS
.R12RSG
0.5
3
**WAVE FUNCTIONS
.CC
*ORBITALS
.MOSTART
 H1DIAG
.FROZEN
 1 0 0 0 
.R12ORB
 1 2 2 2
*SCF INPUT
.THRESHOLD
 1D-10
*CC INPUT
.HERDIR
.MP2
.PRINT
 3
*R12
.R12XXL
.CABS
**END OF DALTON INPUT
%EOF%

#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >r12_orb.check
cat >>r12_orb.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

#
#Noninvariant MP2-R12/B   correlation energy =   -0.165610607
#             MP2-R12/B   correlation energy =   -0.179894117
#Noninvariant MP2-R12/B   correlation energy =   -0.157730789
#             MP2-R12/B   correlation energy =   -0.163731939
#Noninvariant MP2-R12/B   correlation energy =   -0.163669656
#             MP2-R12/B   correlation energy =   -0.172522152
#Noninvariant MP2-R12/B   correlation energy =   -0.163669656
#             MP2-R12/B   correlation energy =   -0.172522152
#
CRIT1=`$GREP "MP2-R12/B   correlation energy =   (-0| -)\.17989411" $log | wc -l`
TEST[1]=`expr	$CRIT1`
CTRL[1]=1
ERROR[1]="Conventional MP2-R12/B ENERGY NOT CORRECT"

CRIT2=`$GREP "MP2-R12/B   correlation energy =   (-0| -)\.16373193" $log | wc -l`
TEST[2]=`expr	$CRIT2`
CTRL[2]=1
ERROR[2]="Ansatz 1 MP2-R12/B ENERGY NOT CORRECT"

CRIT3=`$GREP "MP2-R12/B   correlation energy =   (-0| -)\.17252215" $log | wc -l`
TEST[3]=`expr	$CRIT3`
CTRL[3]=2

ERROR[1]="Ansatz 2/3 MP2-R12/B ENERGY NOT CORRECT"

PASSED=1
for i in 1 2 3
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
#######################################################################
